package com.exercise.widgets.settings

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import com.exercise.widgets.R

class PreferenceFragment : PreferenceFragmentCompat() {

    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
        setPreferencesFromResource(R.xml.root_preferences, rootKey)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        findPreference<EditTextPreference>("signature")?.setOnPreferenceChangeListener { _, newValue ->
            Toast.makeText(context, "$newValue", Toast.LENGTH_SHORT).show()
            true
        }
        findPreference<ListPreference>("reply")?.setOnPreferenceChangeListener { _, newValue ->
            Toast.makeText(context, "$newValue", Toast.LENGTH_SHORT).show()
            true
        }
    }
}